/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.List;

import com.us.usws.common.SiteConstants;
import com.us.usws.dao.MeetingDAO;
import com.us.usws.model.domain.Meeting;
import com.us.usws.service.ro.MeetingROService;
import com.us.usws.support.ext.CacheManager;

/**
 * Service RO impl class
 * @author robot
 */
public class MeetingROServiceImpl implements MeetingROService {

	/**
	 * DAO instance
	 */
	private MeetingDAO dao = new MeetingDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<Meeting> getAllMeetings() {
		List<Meeting> ret = dao.getAllMeetings();
		fillMeetingNamesInList(ret);
		return ret;
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<Meeting> getMeetings(int start, int end) {
		List<Meeting> ret = dao.getMeetings(start, end);
		fillMeetingNamesInList(ret);
		return ret;
	}

	/**
	 * Get Meeting by primary key.
	 */
	@Override
	public Meeting getMeeting(String uid) {
		Meeting m = dao.getMeeting(uid);
		fillMeetingNames(m);
		return m;
	}

	/**
	 * get channel meetings count
	 */
	@Override
	public int getMeetingCountByChannle(String channelUid) {
		return dao.getMeetingCountByChannle(channelUid);
	}

	@Override
	public List<Meeting> getMeetingsByChannel(String channelUid, int start, int size) {
		List<Meeting> ret = dao.getMeetingssByChannel(channelUid, start, size);
		fillMeetingNamesInList(ret);
		return ret;
	}

	@Override
	public int getMeetingCountByPresenterAndType(String userUid, int meetingType) {
		return dao.getMeetingCountByPresenterAndType(userUid, meetingType);
	}

	@Override
	public List<Meeting> getMeetingsByPresenterAndType(String userUid, int meetingtype, int start, int pagesize) {
		List<Meeting> ret = dao.getMeetingsByPresenterAndType(userUid, meetingtype, start, pagesize);
		fillMeetingNamesInList(ret);
		return ret;
	}

	/**
	 * fill meetings list
	 * @param meetings
	 */
	@Override
	public void fillMeetingNamesInList(List<Meeting> meetings) {
		if (meetings != null && !meetings.isEmpty()) {
			for (Meeting each : meetings) {
				fillMeetingNames(each);
			}
		}
	}

	/**
	 * fill meeting names
	 * @param m
	 */
	@Override
	public void fillMeetingNames(Meeting m) {
		String typeName = CacheManager.getDictCache().getDictNameBySepId(SiteConstants.DICT_DOMAIN_MEETING_TYPE, m.getTypeDsid());
		m.setTypeName(typeName);

		String serverTypeName = CacheManager.getDictCache().getDictNameBySepId(SiteConstants.DICT_DOMAIN_MEETING_SERVER_TYPE,
				m.getServerTypeDsid());
		m.setServerTypeName(serverTypeName);

		String statusName = CacheManager.getDictCache().getDictNameBySepId(SiteConstants.DICT_DOMAIN_MEETING_STATUS, m.getStatusDsid());
		m.setStatusName(statusName);

		if (m.getVideoTypeDsid() != null) {
			String videoTypeName = CacheManager.getDictCache().getDictNameBySepId(SiteConstants.DICT_DOMAIN_VIDEO_TYPE,
					m.getVideoTypeDsid());
			m.setVideoTypeName(videoTypeName);
		}

		//user names
		m.setCreateByName(CacheManager.getUserCache().getUserName(m.getCreateByUid()));
		m.setLastUpdByName(CacheManager.getUserCache().getUserName(m.getLastUpdByUid()));
		m.setPresenterName(CacheManager.getUserCache().getUserName(m.getPresenterUid()));
	}

	@Override
	public int getMeetingCountByUsersAny(String uid) {
		return dao.getMeetingCountByUsersAny(uid);
	}

	@Override
	public List<Meeting> getMeetingsByUsersAny(String uid, int start, int pageSize) {
		List<Meeting> ret = dao.getMeetingsByUsersAny(uid, start, pageSize);
		for (Meeting m : ret) {
			fillMeetingNames(m);
		}
		return ret;
	}

	@Override
	public List<Meeting> getMeetingsByChannelAndSeqNum(String channelUid, int seqNum, int start, int pageSize) {
		List<Meeting> ret = dao.getMeetingsByChannelAndSeqNum(channelUid, seqNum, start, pageSize);
		return ret;
	}

	@Override
	public int getMeetingCountByChannelAndSeqNum(String channelUid, int seqNum) {
		return dao.getMeetingCountByChannelAndSeqNum(channelUid, seqNum);
	}

	@Override
	public List<Meeting> getThemeVideos(String themeUid) {
		return dao.getThemeVideos(themeUid);
	}
}